home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE14 / TIPTRIX / LISTINGS.PAS next >
Encoding:
Pascal/Delphi Source File  |  1996-09-07  |  3.5 KB  |  159 lines

  1. { Listing  1 }
  2. procedure CreateModal(FormClass: TFormClass);
  3. begin
  4.   with FormClass.Create(Application) do
  5.   try
  6.     ShowModal
  7.   finally
  8.     Free
  9.   end
  10. end;
  11.  
  12. { Listing 2 }
  13. constructor TmbDBNavigator.Create(AOwner: TComponent);
  14. var
  15.   I: TNavigateBtn;
  16. begin
  17.   inherited Create(AOwner);
  18.   for I := Low(Buttons) to High(Buttons)
  19.   do Buttons[I].OnClick := Click;
  20. end;
  21. procedure TmbDBNavigator.Click(Sender: TObject);
  22. begin
  23.   BtnClick (TNavButton (Sender).Index);
  24. end;
  25.  
  26. { Listing 3 }
  27. {(C) 1996 Pijl Computer Services Ltd. Check laptop power situation}
  28. Unit Power;
  29. Interface
  30. Function PowerMan:Integer;
  31. Implementation
  32. Function PowerMan:Integer;
  33. Var
  34.   Fault,Batt,Life:Byte;
  35. begin
  36.   asm
  37.     mov fault,00h
  38.     mov ax,5300h
  39.     mov bx,0000h
  40.     int 15h
  41.     jc @err
  42.     mov ax,530ah
  43.     mov bx,0001h
  44.     int 15h
  45.     mov batt,bl
  46.     mov life,cl
  47.     jc @err
  48.     jmp @done
  49.     @err: mov fault,AH
  50.     @done: nop
  51.   end;
  52.   If (Fault=0) aAnd (Life in [0..100]) then
  53.     PowerMan := Life
  54.   else
  55.     PowerMan := -1;
  56.  end;
  57. end.
  58.  
  59. { Listing 4 }
  60. type
  61.   PMyRecord = ^TMyRecord;
  62.   TMyRecord = record
  63.     Field : longint;
  64.   end;
  65.   PMyArray = ^TMyArray;
  66.   TMyArray = array[0..100-1] of longint;
  67.   PMySimpleType = ^TMySimpleType;
  68.   TMySimpleType = Double;
  69. var
  70.   tMyRec : TMyRecord;
  71.   pMyRec : PMyRecord;
  72.   tMyArr : TMyArray;
  73.   pMyArr : PMyArray;
  74.   tMySim : TMySimpleType;
  75.   pMySim : PMySimpleType;
  76. procedure NoHat;
  77. begin
  78.   { Initialize pointer variables }
  79.   pMyRec := @tMyRec;
  80.   pMyArr := @tMyArr;
  81.   pMySim := @tMySim;
  82.   { Test normal assignment }
  83.   pMyRec^.Field := 1234567;
  84.   pMyArr^[0] := 1234567;
  85.   pMySim^ := 3.14;
  86.   { Test the no-hat assignment }
  87.   pMyRec.Field := 1234567; { Compiles fine! }
  88.   pMyArr[0] := 1234567; { Compiles fine! }
  89.   { This last one does not compile and should not }
  90.   pMySim := 3.14;
  91. end;
  92.  
  93. { Listing 5 }
  94. type
  95.   TStrong = type Double;
  96.   TWeak     = Double;
  97. procedure CheckWeak(var Strong: TWeak); begin end;
  98. procedure CheckStrong(var Strong: TStrong); begin end;
  99. procedure CheckDouble(var D: Double); begin end;
  100. var
  101.   D: Double;
  102.   S: TStrong;
  103.   W: TWeak;
  104. begin
  105.   CheckDouble(D); { compiles fine }
  106.   CheckDouble(W); { compiles fine }
  107.   CheckDouble(S); { <- compile error }
  108.   CheckWeak(D); { compiles fine }
  109.   CheckWeak(W); { compiles fine }
  110.   CheckWeak(S); { <- compile error }
  111.   CheckStrong(S); { compiles fine }
  112.   CheckStrong(D); { <- compile error }
  113.   CheckStrong(W); { <- compile error }
  114. end.
  115.  
  116. { Listing 6 }
  117. unit NewPC;
  118. interface
  119. uses
  120.   Windows, Messages, SysUtils, Classes, Graphics,
  121.   Controls, Forms, Dialogs, ComCtrls;
  122. type
  123.   TNewPageControl = class(TPageControl)
  124.    private
  125.     procedure CMDialogChar(var Message: TCMDialogChar);
  126.       message CM_DIALOGCHAR;
  127.    protected
  128.    public
  129.    published
  130.  end;
  131. procedure Register;
  132. implementation
  133. procedure Register;
  134. begin
  135.   RegisterComponents('Samples', [TNewPageControl]);
  136. end;
  137. procedure TNewPageControl.CMDialogChar(var Message: TCMDialogChar);
  138. var
  139.   I: Integer;
  140.   S: String;
  141. begin
  142.   if Enabled then with Message do begin
  143.     for I := 0 to PageCount - 1 do begin
  144.       S := Pages[I].Caption;
  145.       if IsAccel(CharCode, S) and Pages[I].TabVisible then begin
  146.         { select the appropriate Tab and give it focus }
  147.         Result := 1; { accelerator key is valid (don't beep) }
  148.         ActivePage := Pages[I];
  149.         if ActivePage = Pages[I] then
  150.           { successfully changed pages }
  151.           Change;
  152.         Exit;
  153.       end;
  154.     end;
  155.   end;
  156.   inherited;
  157. end;
  158. end.
  159.